import {
	defineStore
} from 'pinia';


export const useUserStore = defineStore('user', {
	state: () => ({
		userToken: uni.getStorageSync('userToken') ? uni.getStorageSync('userToken') : {},
		userInfo: uni.getStorageSync('userInfo') ? uni.getStorageSync('userInfo') : {},
	}),
	actions: {
		setUserInfo(userInfo) {
			this.userInfo = userInfo;
		},
		assignUserInfo(userInfo) {
			this.userInfo = {
				...this.userInfo,
				...userInfo,
			}
			uni.setStorageSync('userInfo', userInfo);
		},
		setUserToken(userToken) {
			this.userToken = userToken;
			uni.setStorageSync('userToken', userToken);
		},
		clearUserInfo() {
			this.userInfo = {};
		},
		clearUserToken() {
			this.userToken = '';
		},
		clearAll() {
			this.clearUserInfo();
			this.clearUserToken();
			uni.clearStorageSync();
		},
	},
});